﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//Write a program that calculates the greatest common divisor (GCD) of given two numbers. Use the Euclidean algorithm (find it in Internet).

namespace _08GreatestCommonDivisor
{
    class _08GreatestCommonDivisor
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Calculating the Gretest Common Divisor (GCD) for two integers.");
            Console.Write("First value: ");
            string strFirstValue = Console.ReadLine();
            int fValue = int.Parse(strFirstValue);
            Console.Write("Second value: ");
            string strSecondValue = Console.ReadLine();
            int sValue = int.Parse(strSecondValue);
            if (fValue == 0)
            {
                Console.WriteLine("GCD is " + sValue);
            }
            else if (sValue == 0)
            {
                Console.WriteLine("GCD is " + fValue);
            }
            while ((fValue != 0) && (sValue != 0))
            {
                if (fValue > sValue)
                {
                    fValue = fValue - sValue;
                }
                else
                {
                    sValue = sValue - fValue;
                }
            }
            Console.WriteLine("The GCD is " + fValue);
        }
    }
}
